import Taro from '@tarojs/taro'
import {View} from '@tarojs/components'
import {connect} from '@tarojs/redux'
import ProjectItem from '../../components/project_item'
import {AtActivityIndicator} from 'taro-ui'
import Empty from '../../components/empty'

import './index.less'

@connect(state => ({
  loading: state.loading.effects['project/getByIds'],
  project: state.project,
}))
export default class Index extends Taro.Component {

  config = {
    navigationBarTitleText: '我的关注'
  }

  componentDidShow() {
    const favs = Taro.getStorageSync('favs');
    // const favArray = favs.split(',');
    this.props.dispatch({
      type: 'project/getByIds',
      payload: {
        ids: favs,
      },
    })
  }

  render() {
    const {loading, project: {list}} = this.props;

    return (
      <View className='container'>
        <View className='panel'>
          <View className='body'>
            {
              list.length > 0
              ? list.map(item => <ProjectItem key={item.id} item={item}/>)
              : loading ? <AtActivityIndicator mode='center'/> : <Empty title='您还没有关注的项目哦' desc='去看看吧~'/>
            }
          </View>
        </View>
      </View>
    )
  }
}

